package com.sdlh.demo.pattern.strategy;

import org.springframework.stereotype.Service;

@Service
public class PaymentContext {
    private IPaymentStrategy strategy;

    public void setStrategy(int payType) {
        switch (payType) {
            case 1:
                this.strategy = new AliPay();
                break;
            case 2:
                this.strategy = new WeChatPay();
                break;
            case 3:
                this.strategy = new UnionPay();
                break;
            default:
                throw new IllegalArgumentException("无效的支付类型");
        }
    }

    public void pay(double amount) {
        if (strategy == null) {
            throw new IllegalArgumentException("支付策略未设置");
        }

        strategy.pay(amount);
    }
}
